badblocks: fix infinite loop due to incorrect rounding and overflow#774
Open
blktests-ci[bot] wants to merge 1 commit intolinus-master_basefrom
Open
badblocks: fix infinite loop due to incorrect rounding and overflow#774blktests-ci[bot] wants to merge 1 commit intolinus-master_basefrom
blktests-ci[bot] wants to merge 1 commit intolinus-master_basefrom
Conversation
Author
|
Upstream branch: dd6c438 |
857ada9 to
482ce5b
Compare
Author
|
Upstream branch: dca922e |
7ac44d2 to
6a567cb
Compare
482ce5b to
5a9f7c7
Compare
Author
|
Upstream branch: e75a43c |
6a567cb to
5b169a8
Compare
5a9f7c7 to
25a041f
Compare
Author
|
Upstream branch: 66edb90 |
5b169a8 to
ca2611b
Compare
25a041f to
6f75bd1
Compare
Author
|
Upstream branch: 6d35786 |
ca2611b to
8ad5528
Compare
6f75bd1 to
1f0d33a
Compare
The roundup() and rounddown() macros return the rounded value but do not modify the input in place. In _badblocks_set(), _badblocks_clear(), and badblocks_check(), the return values were being discarded, causing s and target/next to remain unrounded. This resulted in sectors being calculated from unrounded values, which could lead to sectors being way too large (or zero), causing infinite loops in the re_insert/re_clear/re_check loops. Additionally, add integer overflow checks (s > ULLONG_MAX - sectors) before the s + sectors calculation in all three functions to prevent overflow-related issues. Also add early return when sectors becomes zero after rounding in badblocks_check(). Root cause: When s and sectors have specific values (e.g., from syzkaller fuzzing via nvdimm ioctl), the unrounded values cause sectors to be incorrectly calculated. In _badblocks_clear(), this could result in needing 2^46 iterations to process 2^55 sectors, triggering RCU stall warnings and effectively hanging the kernel. Fix by properly capturing the return values from roundup() and rounddown(), adding overflow checks before sector arithmetic, and handling the zero-sectors case in badblocks_check(). Signed-off-by: Ramesh Adhikari <adhikari.resume@gmail.com>
Author
|
Upstream branch: 6d35786 |
8ad5528 to
e16a4aa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request for series with
subject: badblocks: fix infinite loop due to incorrect rounding and overflow
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1086213